package cloud.study.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import po.User;

@RestController
public class RestTemplateController {

    @Autowired
    RestTemplate restTemplate;

    @Value("${server.port}")
    private int port;

    @RequestMapping("/hello")
    public String hello() {
        return restTemplate.getForObject("https://bbs.youxiake.com/api/travel_article/data?act=getMusic&yxkId=2778555799929856", String.class);
    }

    @RequestMapping("/hi")
    public String hi(String name) {
        return "hi :"+name+" 端口"+port;
    }

    @RequestMapping("/testPo")
    public String testPo(@RequestBody User user) {
        return "hi :"+user.getUsername()+"年龄:"+user.getAge()+" 端口"+port;
    }

    @Bean
    public RestTemplate restTemplate() {
       return new RestTemplate();
    }

}
